using System;
using NUnit.Framework;
using ValidationFramework.Configuration;
using ValidationFramework.Extensions;
using ValidationFramework.Reflection;

namespace ValidationFramework.Tests.Configuration
{
    [TestFixture]
    public class ValidatableRuleConfigReaderTest
    {

        #region Methods

        [Test]
        public void ReadConfig1()
        {
            const string validatorXml = "<rule errorMessage='hello' typeName='ValidatableRule' ruleSet='foo' />";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
			var rule = (ValidatableRule)ConfigurationService.GetRule(ruleData, TypePointers.StringTypeHandle);
            Assert.AreEqual("hello", rule.ErrorMessage);
            Assert.IsFalse(rule.UseMemberErrorMessages);
        }


        [Test]
        public void ReadConfig2()
        {
            const string validatorXml = "<rule useMemberErrorMessages='true' typeName='ValidatableRule' ruleSet='foo' />";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
			var rule = (ValidatableRule)ConfigurationService.GetRule(ruleData, TypePointers.StringTypeHandle);
            Assert.IsNull(rule.ErrorMessage);
            Assert.IsTrue(rule.UseMemberErrorMessages);
        }



        [Test]
        [ExpectedException(typeof(InvalidOperationException))]
        public void ReadConfig3()
        {
            const string validatorXml = "<rule useMemberErrorMessages='true' errorMessage='hello' typeName='ValidatableRule' ruleSet='foo' />";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
            ConfigurationService.GetRule(ruleData, typeof(string).TypeHandle);
        }

        #endregion

    }
}